package com.itheima.edu.info.manage.dao;

import com.itheima.edu.info.manage.domain.teacher;

public class teacherDao {
    private static teacher[] teachers = new teacher[5];

    public boolean addTeacher(teacher t) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            teacher teacher = teachers[i];
            if (teacher == null) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            return false;
        } else {
            teachers[index] = t;
            return true;
        }
    }

    public teacher[] findAllTeacher() {
        return teachers;
    }

    public void deleteTeacherById(String id) {
        int index = getIndex(id);
        teachers[index] = null;
    }

    public int getIndex(String id) {
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            teacher t = teachers[i];
            if (t != null && t.getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public void updateTeacher(String id, teacher newTeacher) {
        int index = getIndex(id);
        teachers[index]=newTeacher;
    }
}
